<?php
$websocket = new \swoole_websocket_server("0.0.0.0", 9999);

$websocket->on('connect', function ($server, $fd) {
   echo "111=====connect=====successed===".PHP_EOL;
});

$websocket->on("open", function ($server, $req) {
    echo "222====服务端与客户端建立连接成功===".PHP_EOL;
    var_dump($req);
    $server->push($req->fd,"connect server successed");
});

$websocket->on("message", function ($server, $frame) {
   echo "=====接收到来自客户端消息=====".$frame->data.PHP_EOL;
   $server->push($frame->fd,"server receive message successed");
   var_dump($server->exist($frame->fd));
   var_dump($server->isEstablished($frame->fd));
   $server->disconnect($frame->fd);
   var_dump($server->exist($frame->fd));
   var_dump($server->isEstablished($frame->fd));
});

$websocket->on("close", function ($server, $fd) {
   echo "=====close=====".PHP_EOL;
});

$websocket->start();